home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / UPC12BS1.ZIP / UUCP / UUSTAT.C < prev    next >
C/C++ Source or Header  |  1993-10-02  |  38KB  |  1,091 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    u u s t a t . c                                                 */
  3. /*                                                                    */
  4. /*    Job status report for UUPC/extended                             */
  5. /*                                                                    */
  6. /*                                                                    */
  7. /*    Copyright 1988 (C), Dewey Coffman                               */
  8. /*    Changes Copyright 1991 (C), Andrew H. Derbyshire                */
  9. /*--------------------------------------------------------------------*/
  10.  
  11. /*--------------------------------------------------------------------*/
  12. /*         System include files                                       */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. #include <stdio.h>
  16. #include <io.h>
  17. #include <sys/types.h>
  18. #include <sys/stat.h>
  19. #include <string.h>
  20. #include <time.h>
  21. #include <fcntl.h>
  22. #include <stdlib.h>
  23.  
  24. /*--------------------------------------------------------------------*/
  25. /*         Local include files                                        */
  26. /*--------------------------------------------------------------------*/
  27.  
  28. #include "lib.h"
  29. #include "dater.h"
  30. #include "export.h"
  31. #include "getopt.h"
  32. #include "getseq.h"
  33. #include "hlib.h"
  34. #include "hostable.h"
  35. #include "hostatus.h"
  36. #include "import.h"
  37. #include "pushpop.h"
  38. #include "readnext.h"
  39. #include "security.h"
  40. #include "stater.h"
  41. #include "timestmp.h"
  42.  
  43. #define DAY (60l * 60l * 24l)
  44. #define ALL    "all"
  45. #define MAXL      128      // MAX LINE LENGTH
  46.  
  47. #define STRCREAT(s, s2, s3)\
  48.    strcpy(s, s2);\
  49.    strcat(s, s3);\
  50.  
  51. /*--------------------------------------------------------------------*/
  52. /*                          Local data types                          */
  53. /*--------------------------------------------------------------------*/
  54.  
  55. typedef enum {
  56.       POLL_CALL = 'P',
  57.       RECEIVE_CALL = 'R',
  58.       SEND_CALL = 'S'
  59.       } CALLTYPE;
  60.  
  61.  
  62. struct data_queue {
  63.    char name[FILENAME_MAX];
  64.    struct data_queue *next_link;
  65.    time_t created;
  66.    long size;
  67.    boolean execute;
  68.    char type;
  69. } ;
  70.  
  71. /*--------------------------------------------------------------------*/
  72. /*                             Verb list                              */
  73. /*--------------------------------------------------------------------*/
  74.  
  75. typedef enum {
  76.    LIST_DEFAULT = 1,
  77.    LIST_ALL,
  78.    LIST_ACCESS,
  79.    LIST_QUEUE,
  80.    KILL_JOB,
  81.    REFRESH_JOB,
  82.    FORCE_POLL
  83.    } COMMAND_CLASS;
  84.  
  85. /*--------------------------------------------------------------------*/
  86. /*                Processing to be taken by open_call                 */
  87. /*--------------------------------------------------------------------*/
  88.  
  89. typedef enum {
  90.    JOB_STATUS = 1,
  91.    JOB_KILL,
  92.    JOB_REFRESH
  93.    } CALL_ACTION;
  94.  
  95. /*--------------------------------------------------------------------*/
  96. /*                          Global variables                          */
  97. /*--------------------------------------------------------------------*/
  98.  
  99. currentfile();
  100.  
  101. static const char *host_status[] = {
  102.       "(invalid - entry not properly initialized)",
  103.       "(local host system)",
  104.       "(host for gateway purposes only)",
  105.       "Never called",
  106.       "Dialing now",
  107.       "Invalid device or speed in SYSTEMS file",
  108.       "Device not available",
  109.       "Conversation start-up failed",
  110.       "Talking",
  111.       "Callback required",
  112.       "Modem initialization script failed",
  113.       "Dial failed",
  114.       "Script failed",
  115.       "Max retry reached",
  116.       "Retry time not reached",
  117.       "Call succeeded",
  118.       "Wrong machine name",
  119.       "Unknown host",
  120.       "Failed",
  121.       "Wrong time to call",
  122.       "(call successed, entry not reset)",
  123.    } ;
  124.  
  125. /*--------------------------------------------------------------------*/
  126. /*                        Internal prototypes                         */
  127. /*--------------------------------------------------------------------*/
  128.  
  129. static void all( const char *system, const char *userid );
  130.  
  131. static char *is_job(const char *jobid );
  132.  
  133. static void kill_job(const char *s);
  134.  
  135. static void long_stats( const char *system );
  136.  
  137. static void short_stats( const char *system );
  138.  
  139. static CALLTYPE open_call( const char *callname,
  140.                            const char *remote,
  141.                                  struct data_queue **current,
  142.                                  char *user,
  143.                                  char *sys,
  144.                            const CALL_ACTION action);
  145.  
  146. static void open_data(const char *file,
  147.                             char *user,
  148.                             char *sys,
  149.                             char *command);
  150.  
  151. static void poll(const char *callee);
  152.  
  153. static void print_all(       char *job,
  154.                        struct data_queue *current,
  155.                        const char *user,
  156.                        const char *sys);
  157.  
  158. static void refresh_job(const char *s);
  159.  
  160. static void touch( const char *fname );
  161.  
  162. static void usage( void );
  163.  
  164. /*--------------------------------------------------------------------*/
  165. /*    m a i n                                                         */
  166. /*                                                                    */
  167. /*    main program                                                    */
  168. /*--------------------------------------------------------------------*/
  169.  
  170. void main(int  argc, char  **argv)
  171. {
  172.    int c;
  173.    extern char *optarg;
  174.    extern int   optind;
  175.    COMMAND_CLASS command = LIST_DEFAULT;
  176.  
  177.    char *system = NULL;
  178.    char *userid = NULL;
  179.    char *job    = NULL;
  180.  
  181. /*--------------------------------------------------------------------*/
  182. /*     Report our version number and date/time compiled               */
  183. /*--------------------------------------------------------------------*/
  184.  
  185.    debuglevel = 0;
  186.    banner( argv );
  187.  
  188. #if defined(__CORE__)
  189.    copywrong = strdup(copyright);
  190.    checkref(copywrong);
  191. #endif
  192.  
  193.    if (!configure( B_UUSTAT ))
  194.       exit(1);   /* system configuration failed */
  195.  
  196. /*--------------------------------------------------------------------*/
  197. /*                   Switch to the spool directory                    */
  198. /*--------------------------------------------------------------------*/
  199.  
  200.    tzset();                      // Set up time zone information
  201.    PushDir( E_spooldir );
  202.    atexit( PopDir );
  203.  
  204. /*--------------------------------------------------------------------*/
  205. /*        Process our arguments                                       */
  206. /*--------------------------------------------------------------------*/
  207.  
  208.    while ((c = getopt(argc, argv, "amqk:r:s:u:x:P:")) !=  EOF)
  209.       switch(c) {
  210.       case 'a':
  211.          command = LIST_ALL;
  212.          break;
  213.  
  214.       case 'm':
  215.          command = LIST_ACCESS;
  216.          system = optarg;
  217.          break;
  218.  
  219.       case 'q':
  220.          command = LIST_QUEUE;
  221.          break;
  222.  
  223.       case 'k':
  224.          command = KILL_JOB;
  225.          job = optarg;
  226.          break;
  227.  
  228.       case 'r':
  229.          command = REFRESH_JOB;
  230.          job = optarg;
  231.          break;
  232.  
  233.       case 's':
  234.          if ( system != NULL )
  235.          {
  236.             printmsg(0,"Invalid or duplicate option -s %s",optarg);
  237.             usage();
  238.          }
  239.          system = optarg;
  240.          break;
  241.  
  242.       case 'u':
  243.          userid = optarg;
  244.          break;
  245.  
  246.       case 'x':
  247.          debuglevel = atoi( optarg );
  248.          break;
  249.  
  250.       case 'P':
  251.          command = FORCE_POLL;
  252.          if ( system != NULL )
  253.          {
  254.             printmsg(0,"Invalid or duplicate option -P %s",optarg);
  255.             usage();
  256.          }
  257.          system = optarg;
  258.          break;
  259.  
  260.       case '?':
  261.          usage();
  262.    }
  263.  
  264.    if (optind != argc) {
  265.       puts("Extra parameter(s) at end.");
  266.       exit(2);
  267.    }
  268.  
  269. /*--------------------------------------------------------------------*/
  270. /*                 Determine if we have a valid host                  */
  271. /*-----------------------------------------